﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ICTBilling;

/// <summary>
/// Summary description for Standard
/// </summary>
public partial class tbStandard : IValidate
{
    public List<ExceptionHandler> Validate(ChangeAction changeAction)
    {
        List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
        try
        {
            if (changeAction == ChangeAction.Insert ||
                changeAction == ChangeAction.Update)
            {
                if (changeAction == ChangeAction.Update && this.PkStandardID == null)
                    ExecutionCollection.Add(new ExceptionHandler("PkStandardID", "شناسه استاندارد", ICTBilling.ExceptionType.NullArgumant));

                if (this.FkCenterID == null)
                    ExecutionCollection.Add(new ExceptionHandler("FkCenterID", "نام مرکز", ICTBilling.ExceptionType.NullArgumant));

                if (this.StartDate == null)
                    ExecutionCollection.Add(new ExceptionHandler("StartDate", "از تاریخ", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        DateTime.Parse(this.StartDate.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("StartDate", "از تاریخ", ICTBilling.ExceptionType.DateFormat));
                    }
                }

                if (this.EndDate == null)
                    ExecutionCollection.Add(new ExceptionHandler("EndDate", "تا تاریخ", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        DateTime.Parse(this.EndDate.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("EndDate", "تا تاریخ", ICTBilling.ExceptionType.DateFormat));
                    }
                }

                if (this.Type == null)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.NullArgumant));
                else if (this.Type > 255 || this.Type < 1)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.ShortFormat));
                else
                {
                    try
                    {
                        byte.Parse(this.Type.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("Type", "نوع انرژی", ICTBilling.ExceptionType.ShortFormat));
                    }
                }

                if (this.MinPerPerson == null)
                    ExecutionCollection.Add(new ExceptionHandler("MinPerPerson", "کمینه مصرف هر نفر", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.MinPerPerson.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("MinPerPerson", "کمینه مصرف هر نفر", ICTBilling.ExceptionType.IntFormat));
                    }
                }

                if (this.MaxPerPerson == null)
                    ExecutionCollection.Add(new ExceptionHandler("MaxPerPerson", "بیشینه مصرف هر نفر", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.MaxPerPerson.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("MaxPerPerson", "بیشینه مصرف هر نفر", ICTBilling.ExceptionType.IntFormat));
                    }
                }

                if (this.MinEquipment == null)
                    ExecutionCollection.Add(new ExceptionHandler("MinEquipment", "کمینه مصرف تجهیزات", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.MinEquipment.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("MinEquipment", "کمینه مصرف تجهیزات", ICTBilling.ExceptionType.IntFormat));
                    }
                }


                if (this.MaxEquipment == null)
                    ExecutionCollection.Add(new ExceptionHandler("MaxEquipment", "بیشینه مصرف تجهیزات", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.MaxEquipment.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("MaxEquipment", "بیشینه مصرف تجهیزات", ICTBilling.ExceptionType.IntFormat));
                    }
                }
            }
        }
        catch (Exception _Exception)
        {
            ExecutionCollection.Add(new ExceptionHandler(_Exception));
        }
        return ExecutionCollection;
    }
}